﻿
@{
    ViewData["Title"] = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div id="appFriendlyLink" style="margin:2px;padding:2px;">
    <el-form inline label-position="right" label-width="80px" class="query-form">
        <el-form-item label="关键字">
            <el-input placeholder="请输入关键字" style="width:150px;" v-model="keyword"></el-input>
        </el-form-item>
        <el-form-item label="状态">
            <el-select v-model="enabled">
                <el-option label="全部" value="null"></el-option>
                <el-option label="启用" value="true"></el-option>
                <el-option label="禁用" value="false"></el-option>
            </el-select>
        </el-form-item> 
        <el-form-item>
            <el-button type="success" size="small" @@click="FriendlyLinkEdit(null)" v-show="pageButtons.includes('addfriendlylink')">新增</el-button>
            <el-button type="primary" size="small" @@click="handleSearch">查询</el-button>
        </el-form-item>
    </el-form>
    <el-table :data="tableData" id="table" stripe border style="width:100%" size="mini">
        <el-table-column type="index" width="50" align="center"></el-table-column>
        <el-table-column prop="name" label="名称" width="180"></el-table-column>
        <el-table-column prop="url" label="链接" width="180"></el-table-column>
        <el-table-column label="状态" width="100" align="center">
            <template slot-scope="scope">
                <el-button type="success" round size="mini" v-if="scope.row.enabled==true">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
                <el-button type="danger" round size="mini" v-if="scope.row.enabled==false">{{scope.row.enabled === false ? '禁用' : '启用'}}</el-button>
            </template>
        </el-table-column>
        <el-table-column prop="orderIndex" label="排序" width="180"></el-table-column>
        <el-table-column prop="remark" label="备注" width="180"></el-table-column> 
        <el-table-column prop="createTime" label="创建时间" width="200" align="center"></el-table-column>
        <el-table-column prop="updateTime" label="修改时间" width="200" align="center"></el-table-column>
        <el-table-column fixed="right" label="操作" width="450" align="center">
            <template slot-scope="scope">
                <el-button :type="scope.row.enabled === true?'danger':'success'" @@click="SetEnabled(scope.row)" size="mini" v-show="pageButtons.includes('setfriendlylinkenabled')">
                    <span>{{scope.row.enabled === true ? '禁用' : '启用'}}</span>
                </el-button>
                <el-button type="primary" size="mini" @@click="FriendlyLinkEdit(scope.row )" v-show="pageButtons.includes('editfriendlylink')">修改</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination @@size-change="handleSizeChange"
                   @@current-change="handleCurrentChange"
                   :current-page="currentPage"
                   :page-sizes="[10, 20, 50, 100]"
                   :page-size="10"
                   layout="total, sizes, prev, pager, next, jumper"
                   :total="total">
    </el-pagination>
</div>
<script>
    function refreshFromChild() {
        vueRole.GetFriendlyLinkList();
    }

    var vueRole = new Vue({
        el: '#appFriendlyLink',
        data() {
            return {
                pageButtons: [],
                 

                keyword: '',
                enabled: 'null', 
                pageSize: 10,
                currentPage: 1,
                total: 0,
                tableData: [],
                  
            }
        },
        created(){
            var _this = this;
            this.GetFriendlyLinkList(); 
            _this.$getMenuButtons();
        },
        methods: { 
            FriendlyLinkEdit(row) {
                var id = 0;
                if (row) id = row.id;
                this.$addTab(id, id == 0 ? "新增资讯" : "修改资讯", "../Friendlylink/edit?id=" + id);
            },
             projectDetail(row ) {
                 this.$addTab(row.id, "资讯详情", "../Friendlylink/detail?id=" + row.id);
            },
            tableRowClassName({ row, rowIndex }) {
                if (rowIndex === 1) {
                    return 'warning-row';
                } else if (rowIndex === 3) {
                    return 'success-row';
                }
                return '';
            },
            handleSearch() {
                this.GetFriendlyLinkList();
            },
            handleClick(row) {
                console.log(row);
            },
            GetFriendlyLinkList() {
                  var _this = this;
                 _this.$post("@Url.Action("GetFriendlylinkPagedList", "Friendlylink")", {
                     PageIndex: _this.currentPage,
                     PageSize: _this.pageSize,
                     Keyword: _this.keyword, 
                     enabled: _this.enabled == 'null' ? null : _this.enabled == "true" ? true : false,
                     order: [ 
                         { FieldName: "Id", Order: "Desc" }
                     ]
                 }).then((response) => {
                        _this.tableData = response.items;
                        _this.total = response.totalCount;

                     _this.$nextTick(() => {
                         _this.$refs["table"].doLayout()
                     })
                  }).catch((error) => {
                  });
            },
            SetEnabled(row) {
                  var _this = this;
                _this.$post("@Url.Action("SetFriendlyLinkEnabled", "Friendlylink")?id=" + row.id + "&enabled=" + !(row.enabled)).then((res) => {
                      _this.$success(res.message, function () {
                          if(res.success)
                              _this.GetFriendlyLinkList();
                      });


                  }).catch((error) => {
                  });
            },
            handleSizeChange(val) {
                this.pageSize = val;
                this.GetFriendlyLinkList();
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.GetFriendlyLinkList();
            }
        }
    });
</script>